<!--
  ~ Copyright (c) 2022, Nordic Semiconductor
  ~ All rights reserved.
  ~
  ~ Redistribution and use in source and binary forms, with or without modification, are
  ~ permitted provided that the following conditions are met:
  ~
  ~ 1. Redistributions of source code must retain the above copyright notice, this list of
  ~ conditions and the following disclaimer.
  ~
  ~ 2. Redistributions in binary form must reproduce the above copyright notice, this list
  ~ of conditions and the following disclaimer in the documentation and/or other materials
  ~ provided with the distribution.
  ~
  ~ 3. Neither the name of the copyright holder nor the names of its contributors may be
  ~ used to endorse or promote products derived from this software without specific prior
  ~ written permission.
  ~
  ~ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ~ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  ~ TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  ~ PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ~ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ~ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ~ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  ~ OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  ~ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  ~ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  ~ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  -->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_152-release) on Fri Nov 17 17:43:02 CET 2017 -->
<title>HexInputStream</title>
<meta name="date" content="2017-11-17">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../../../script.js"></script>
</head>
<body>
<script type="text/javascript"><!--
    try {
        if (location.href.indexOf('is-external=true') == -1) {
            parent.document.title="HexInputStream";
        }
    }
    catch(err) {
    }
//-->
var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor";
var rowColor = "rowColor";
var tableTab = "tableTab";
var activeTableTab = "activeTableTab";
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="topNav"><a name="navbar.top">
<!--   -->
</a>
<div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.top.firstrow">
<!--   -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-files/index-1.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../no/nordicsemi/android/dfu/internal/ArchiveInputStream.html" title="class in no.nordicsemi.android.dfu.internal"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li>Next&nbsp;Class</li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?no/nordicsemi/android/dfu/internal/HexInputStream.html" target="_top">Frames</a></li>
<li><a href="HexInputStream.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_top");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li><a href="#fields.inherited.from.class.java.io.FilterInputStream">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.top">
<!--   -->
</a></div>
<!-- ========= END OF TOP NAVBAR ========= -->
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="subTitle">no.nordicsemi.android.dfu.internal</div>
<h2 title="Class HexInputStream" class="title">Class HexInputStream</h2>
</div>
<div class="contentContainer">
<ul class="inheritance">
<li>java.lang.Object</li>
<li>
<ul class="inheritance">
<li>java.io.InputStream</li>
<li>
<ul class="inheritance">
<li>java.io.FilterInputStream</li>
<li>
<ul class="inheritance">
<li>no.nordicsemi.android.dfu.internal.HexInputStream</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<div class="description">
<ul class="blockList">
<li class="blockList">
<dl>
<dt>All Implemented Interfaces:</dt>
<dd>java.io.Closeable, java.lang.AutoCloseable</dd>
</dl>
<hr>
<br>
<pre>public class <span class="typeNameLabel">HexInputStream</span>
extends java.io.FilterInputStream</pre>
<div class="block">Reads the binary content from the HEX file using IntelHex standard: http://www.interlog.com/~speff/usefulinfo/Hexfrmt.pdf.
 Truncates the HEX file from all meta data and returns only the BIN content.
 <p>
 In nRF51 chips memory a SoftDevice starts at address 0x1000. From 0x0000 to 0x1000 there is MBR sector (since SoftDevice 7.0.0) which should not be transmitted using DFU. Therefore this class skips
 all data from addresses below 0x1000.
 </p></div>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">
<!-- =========== FIELD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="field.summary">
<!--   -->
</a>
<h3>Field Summary</h3>
<ul class="blockList">
<li class="blockList"><a name="fields.inherited.from.class.java.io.FilterInputStream">
<!--   -->
</a>
<h3>Fields inherited from class&nbsp;java.io.FilterInputStream</h3>
<code>in</code></li>
</ul>
</li>
</ul>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.summary">
<!--   -->
</a>
<h3>Constructor Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation">
<caption><span>Constructors</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colOne" scope="col">Constructor and Description</th>
</tr>
<tr class="altColor">
<td class="colOne"><code><span class="memberNameLink"><a href="../../../../../no/nordicsemi/android/dfu/internal/HexInputStream.html#HexInputStream-byte:A-int-">HexInputStream</a></span>(byte[]&nbsp;data,
              int&nbsp;mbrSize)</code>&nbsp;</td>
</tr>
<tr class="rowColor">
<td class="colOne"><code><span class="memberNameLink"><a href="../../../../../no/nordicsemi/android/dfu/internal/HexInputStream.html#HexInputStream-java.io.InputStream-int-">HexInputStream</a></span>(java.io.InputStream&nbsp;in,
              int&nbsp;mbrSize)</code>
<div class="block">Creates the HEX Input Stream.</div>
</td>
</tr>
</table>
</li>
</ul>
<!-- ========== METHOD SUMMARY =========== -->
<ul class="blockList">
<li class="blockList"><a name="method.summary">
<!--   -->
</a>
<h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th>
</tr>
<tr id="i0" class="altColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../no/nordicsemi/android/dfu/internal/HexInputStream.html#available--">available</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i1" class="rowColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../no/nordicsemi/android/dfu/internal/HexInputStream.html#read--">read</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i2" class="altColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../no/nordicsemi/android/dfu/internal/HexInputStream.html#read-byte:A-">read</a></span>(byte[]&nbsp;buffer)</code>&nbsp;</td>
</tr>
<tr id="i3" class="rowColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../no/nordicsemi/android/dfu/internal/HexInputStream.html#read-byte:A-int-int-">read</a></span>(byte[]&nbsp;buffer,
    int&nbsp;offset,
    int&nbsp;count)</code>&nbsp;</td>
</tr>
<tr id="i4" class="altColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../no/nordicsemi/android/dfu/internal/HexInputStream.html#readPacket-byte:A-">readPacket</a></span>(byte[]&nbsp;buffer)</code>
<div class="block">Fills the buffer with next bytes from the stream.</div>
</td>
</tr>
<tr id="i5" class="rowColor">
<td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../no/nordicsemi/android/dfu/internal/HexInputStream.html#reset--">reset</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i6" class="altColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../no/nordicsemi/android/dfu/internal/HexInputStream.html#sizeInBytes--">sizeInBytes</a></span>()</code>
<div class="block">Returns the total number of bytes.</div>
</td>
</tr>
<tr id="i7" class="rowColor">
<td class="colFirst"><code>int</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../../../../no/nordicsemi/android/dfu/internal/HexInputStream.html#sizeInPackets-int-">sizeInPackets</a></span>(int&nbsp;packetSize)</code>
<div class="block">Returns the total number of packets with given size that are needed to get all available data</div>
</td>
</tr>
</table>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.io.FilterInputStream">
<!--   -->
</a>
<h3>Methods inherited from class&nbsp;java.io.FilterInputStream</h3>
<code>close, mark, markSupported, skip</code></li>
</ul>
<ul class="blockList">
<li class="blockList"><a name="methods.inherited.from.class.java.lang.Object">
<!--   -->
</a>
<h3>Methods inherited from class&nbsp;java.lang.Object</h3>
<code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<ul class="blockList">
<li class="blockList"><a name="constructor.detail">
<!--   -->
</a>
<h3>Constructor Detail</h3>
<a name="HexInputStream-java.io.InputStream-int-">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>HexInputStream</h4>
<pre>public&nbsp;HexInputStream(java.io.InputStream&nbsp;in,
                      int&nbsp;mbrSize)
               throws <a href="../../../../../no/nordicsemi/android/dfu/internal/exception/HexFileValidationException.html" title="class in no.nordicsemi.android.dfu.internal.exception">HexFileValidationException</a>,
                      java.io.IOException</pre>
<div class="block">Creates the HEX Input Stream. The constructor calculates the size of the BIN content which is available through <a href="../../../../../no/nordicsemi/android/dfu/internal/HexInputStream.html#sizeInBytes--"><code>sizeInBytes()</code></a>. If HEX file is invalid then the bin size is 0.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>in</code> - the input stream to read from</dd>
<dd><code>mbrSize</code> - The MBR (Master Boot Record) size in bytes. Data with addresses below than number will be trimmed and not transferred to DFU target.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="../../../../../no/nordicsemi/android/dfu/internal/exception/HexFileValidationException.html" title="class in no.nordicsemi.android.dfu.internal.exception">HexFileValidationException</a></code> - if HEX file is invalid. F.e. there is no semicolon (':') on the beginning of each line.</dd>
<dd><code>java.io.IOException</code> - if the stream is closed or another IOException occurs.</dd>
</dl>
</li>
</ul>
<a name="HexInputStream-byte:A-int-">
<!--   -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>HexInputStream</h4>
<pre>public&nbsp;HexInputStream(byte[]&nbsp;data,
                      int&nbsp;mbrSize)
               throws <a href="../../../../../no/nordicsemi/android/dfu/internal/exception/HexFileValidationException.html" title="class in no.nordicsemi.android.dfu.internal.exception">HexFileValidationException</a>,
                      java.io.IOException</pre>
<dl>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code><a href="../../../../../no/nordicsemi/android/dfu/internal/exception/HexFileValidationException.html" title="class in no.nordicsemi.android.dfu.internal.exception">HexFileValidationException</a></code></dd>
<dd><code>java.io.IOException</code></dd>
</dl>
</li>
</ul>
</li>
</ul>
<!-- ============ METHOD DETAIL ========== -->
<ul class="blockList">
<li class="blockList"><a name="method.detail">
<!--   -->
</a>
<h3>Method Detail</h3>
<a name="available--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>available</h4>
<pre>public&nbsp;int&nbsp;available()</pre>
<dl>
<dt><span class="overrideSpecifyLabel">Overrides:</span></dt>
<dd><code>available</code>&nbsp;in class&nbsp;<code>java.io.FilterInputStream</code></dd>
</dl>
</li>
</ul>
<a name="readPacket-byte:A-">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>readPacket</h4>
<pre>public&nbsp;int&nbsp;readPacket(byte[]&nbsp;buffer)
               throws <a href="../../../../../no/nordicsemi/android/dfu/internal/exception/HexFileValidationException.html" title="class in no.nordicsemi.android.dfu.internal.exception">HexFileValidationException</a>,
                      java.io.IOException</pre>
<div class="block">Fills the buffer with next bytes from the stream.</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>buffer</code> - buffer to be filled</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the size of the buffer</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.io.IOException</code></dd>
<dd><code><a href="../../../../../no/nordicsemi/android/dfu/internal/exception/HexFileValidationException.html" title="class in no.nordicsemi.android.dfu.internal.exception">HexFileValidationException</a></code></dd>
</dl>
</li>
</ul>
<a name="read--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>read</h4>
<pre>public&nbsp;int&nbsp;read()
         throws java.io.IOException</pre>
<dl>
<dt><span class="overrideSpecifyLabel">Overrides:</span></dt>
<dd><code>read</code>&nbsp;in class&nbsp;<code>java.io.FilterInputStream</code></dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.io.IOException</code></dd>
</dl>
</li>
</ul>
<a name="read-byte:A-">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>read</h4>
<pre>public&nbsp;int&nbsp;read(byte[]&nbsp;buffer)
         throws java.io.IOException</pre>
<dl>
<dt><span class="overrideSpecifyLabel">Overrides:</span></dt>
<dd><code>read</code>&nbsp;in class&nbsp;<code>java.io.FilterInputStream</code></dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.io.IOException</code></dd>
</dl>
</li>
</ul>
<a name="read-byte:A-int-int-">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>read</h4>
<pre>public&nbsp;int&nbsp;read(byte[]&nbsp;buffer,
                int&nbsp;offset,
                int&nbsp;count)
         throws java.io.IOException</pre>
<dl>
<dt><span class="overrideSpecifyLabel">Overrides:</span></dt>
<dd><code>read</code>&nbsp;in class&nbsp;<code>java.io.FilterInputStream</code></dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.io.IOException</code></dd>
</dl>
</li>
</ul>
<a name="sizeInBytes--">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>sizeInBytes</h4>
<pre>public&nbsp;int&nbsp;sizeInBytes()</pre>
<div class="block">Returns the total number of bytes.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>total number of bytes available</dd>
</dl>
</li>
</ul>
<a name="sizeInPackets-int-">
<!--   -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>sizeInPackets</h4>
<pre>public&nbsp;int&nbsp;sizeInPackets(int&nbsp;packetSize)
                  throws java.io.IOException</pre>
<div class="block">Returns the total number of packets with given size that are needed to get all available data</div>
<dl>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>packetSize</code> - the maximum packet size</dd>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the number of packets needed to get all the content</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.io.IOException</code></dd>
</dl>
</li>
</ul>
<a name="reset--">
<!--   -->
</a>
<ul class="blockListLast">
<li class="blockList">
<h4>reset</h4>
<pre>public&nbsp;void&nbsp;reset()
           throws java.io.IOException</pre>
<dl>
<dt><span class="overrideSpecifyLabel">Overrides:</span></dt>
<dd><code>reset</code>&nbsp;in class&nbsp;<code>java.io.FilterInputStream</code></dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>java.io.IOException</code></dd>
</dl>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
<!-- ========= END OF CLASS DATA ========= -->
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<div class="bottomNav"><a name="navbar.bottom">
<!--   -->
</a>
<div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a name="navbar.bottom.firstrow">
<!--   -->
</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../overview-summary.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../index-files/index-1.html">Index</a></li>
<li><a href="../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList">
<li><a href="../../../../../no/nordicsemi/android/dfu/internal/ArchiveInputStream.html" title="class in no.nordicsemi.android.dfu.internal"><span class="typeNameLink">Prev&nbsp;Class</span></a></li>
<li>Next&nbsp;Class</li>
</ul>
<ul class="navList">
<li><a href="../../../../../index.html?no/nordicsemi/android/dfu/internal/HexInputStream.html" target="_top">Frames</a></li>
<li><a href="HexInputStream.html" target="_top">No&nbsp;Frames</a></li>
</ul>
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../allclasses-noframe.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_bottom");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li><a href="#fields.inherited.from.class.java.io.FilterInputStream">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor.summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.summary">Method</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor.detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method.detail">Method</a></li>
</ul>
</div>
<a name="skip.navbar.bottom">
<!--   -->
</a></div>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
</body>
</html>
